All Questions
Tagged with time-limit-exceededrecursion
25 questions
4votes
2answers
131views
Find largest sum not involving consecutive values
There is a question to basically find the largest sum in an array, such that no two elements are chosen adjacent to each other. The concept is to recursively calculate the sum, while considering and ...
2votes
1answer
194views
k-dice Ways to get a target value
I'm trying to solve the following problem: You have a k-dice. A k-dice is a dice which have k-faces and each face have value written from 1 to k. Eg. A 6-dice is the normal dice we use while playing ...
3votes
1answer
1kviews
Knock down tall buildings
I'm trying to solve the following problem: As you know Bob likes to destroy the buildings. There are N buildings in a city, ith building has ai floors. Bob can do the following operation. Choose a ...
3votes
1answer
225views
LeetCode - Weekly Contest 213 - Kth Smallest Instructions
Hi I participated in Leetcode weekly contest 213 and am facing issue with submission for below question Kth Smallest Instructions Bob is standing at cell (0, 0), and he wants to reach destination: (...
1vote
2answers
247views
Recursive brute-force approach to maximum points you can obtain from cards
I came across this question on Leetcode. The question description is as follows: There are several cards arranged in a row, and each card has an associated number of points. The points are given in ...
21votes
3answers
4kviews
Loading military units into ships optimally, using backtracking
I solved the following problem using backtracking: We are given a list of military units, their weight and their (numerical) strength. We have a number of ships with a limited carrying capacity. ...
2votes
3answers
992views
Looking for all numbers where each digit is bigger than the previous digit
This is the "Increasing Number problem", where we are looking for all numbers with \$n\$ digits where each digit is bigger than the digit before it. Or in Mathematical therms where: $$\mathit{...
4votes
3answers
8kviews
Knapsack problem - recursive approach with memoization
This post is based on the 0-1 Knapsack problem. I came across this problem in Assignment #4 of Professor Tim Roughgarden's course Greedy Algorithms, Minimum Spanning Trees, and Dynamic Programming on ...
3votes
3answers
386views
Find k-distinct partitions which contain at least two perfect squares
Problem Statement: A k-distinct-partition of a number \$n\$ is a set of \$k\$ distinct positive integers that add up to \$n\$. For example, the 3-distinct partitions of 10 are \$1+2+7\$ \$1+...
3votes
3answers
3kviews
Finding all possible paths between two points in a grid using recursion
I'm trying to find all possible paths made of 0 from bottom left to top right, only by moving either up or to the right. The input file contains a grid of characters, where ...
2votes
2answers
775views
Find subsets of size K in N set
The question is: There is a set An, and it consists of integers from 1 to n. ...
11votes
2answers
5kviews
Lovely Lucky LAMBs
I am trying to solve this question from google's foobar. However, my code exceeds the time limit, even though when I tested it I got correct answers. How can I make my code more efficient? Lovely ...
5votes
5answers
7kviews
Finding large Fibonacci Number in Python
I'm doing Project Euler at 1000-digit Fibonacci number - Problem 25 which says The Fibonacci sequence is defined by the recurrence relation: Fn = Fn−1 + Fn−2, where F1 = 1 and F2 = 1. ...
2votes
1answer
508views
How many ways we can make the change of the amount using the coins given
Given a set of coins and amount, write an algorithm to find out how many ways we can make the change of the amount using the coins given. Example: Amount = 5 ...
1vote
0answers
898views
Hackerrank > Woman's CodeSprint 2 > stone division, Revisited ( recursive function)
Problem statement You have a pile of n stones that you want to split into multiple piles, as well as a set, S, of ...